<template>
        <el-dialog top="5%" title="新增" v-model="editFormVisible" :close-on-click-modal="false">
            <el-form ref="form" :model="form" :rules="rules" label-width="110px">
                <el-form-item label="跟进时间" prop="FCreateDate">
                    <el-date-picker :disabled="true" type="date" placeholder="选择日期" v-model="form.FCreateDate"  style="width: 100%"></el-date-picker>
                </el-form-item>
                <el-form-item label="客方联系人"  prop="FLinkMan">
                    <sy-select v-model="form.FLinkMan"  valueKey="FName" @change="linkManChange"
                               :optionData="'server/customer/Contacts.ashx?cmd=GetOptions&custID='+form.FCustID">
                    </sy-select>
                </el-form-item>
                <el-form-item label="客方联系电话" prop="FLinkPhone">
                    <el-input v-model="form.FLinkPhone"></el-input>
                </el-form-item>
                <el-form-item label="通话时长(分钟)" prop="FTalkTime">
                    <el-input-number v-model="form.FTalkTime"></el-input-number>
                    <el-tag type="gray">请准确填写通话时长，没接通填0，一分钟之内填1，一到二分钟之内填2，以此类推</el-tag>
                </el-form-item>
                <!--<el-form-item label="跟进主题"  prop="FTitle">-->
                    <!--<sy-select v-model="form.FTitle"  valueKey="FName"-->
                               <!--optionData="server/system/SetType.ashx?cmd=GetOptions&FType=8">-->
                    <!--</sy-select>-->
                <!--</el-form-item>-->
                <el-form-item label="跟进内容" prop="FContent">
                    <el-input  :autosize="{ minRows: 2}" type="textarea" v-model="form.FContent"></el-input>
                </el-form-item>
                <el-form-item label="拨出电话号码" prop="FMyPhone">
                    <el-input v-model="form.FMyPhone"></el-input>
                </el-form-item>
                <el-form-item label="再跟进时间">
                    <el-date-picker  type="date" placeholder="选择日期" v-model="form.FToDate"  style="width: 100%"></el-date-picker>
                </el-form-item>
                <el-form-item label="跟进人" prop="FUserID">
                    <sy-select :disabled="true"  v-model="form.FUserID"
                               optionData="server/system/User.ashx?cmd=GetUserOptions">
                    </sy-select>
                </el-form-item>
                <el-form-item label="真实名字" v-if="names.length>1">
                    <el-radio-group v-model="form.FRealName">
                        <el-radio v-for="item in names" :label="item"></el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="editFormVisible = false">取 消</el-button>
                <el-button v-if="authEdit" type="primary" @click="save" :loading="loading">保存</el-button>
            </div>
      </el-dialog>
</template>

<script>
    import util from '../../common/util'
    export default {
        data() {
            return {
                authEdit:false,
                form: {},
                names:[],
                rules: {
                    FLinkMan: [{required: true,message: '请输入客方联系人', trigger: 'change'}],
                    FLinkPhone: [{required: true,message: '请输入客方联系电话', trigger: 'change'}],
                    FMyPhone: [{required: true,message: '拨出电话号码', trigger: 'change'}],
                    FTitle: [{required: true,message: '请输入跟进主题', trigger: 'change'}],
                    FContent: [{required: true,message: '请输入跟进内容', trigger: 'change'}],
                    FTalkTime: [{required: true,type:"integer",min:0, message: '必须大于等于0', trigger: 'change'}]
                },
                loading:false,
                editFormVisible:false
            }
        },
        methods: {
            switchLoading(flag){
                this.loading = flag;
            },
            _openEdit(record,authEdit) {
                this.authEdit = authEdit
                this.editFormVisible = true
                this.form = Object.assign({},record)
                //真实名字默认第一个
                if(this.form.UserRealName){
                    this.names = this.form.UserRealName.split(",")
                }
            },
            _openAdd(record) {
                this.authEdit = true
                this.editFormVisible = true
                let form = {FID:0,
                    FCreateDate:global.sysParam.ServerDate,
                    FToDate:null,
                    FLinkPhone:"",
                    FType:0,
                    FMyPhone:global.user.FTelPhone,
                    FTalkTime:0,
                    FUserID:global.user.FID
                }
                //真实名字默认第一个
                if(global.user.FRealName){
                     this.names = global.user.FRealName.split(",")
                     form.FRealName = this.names[0]
                }
                this.form = Object.assign(form,record)
            },
            save:function () {
                util.saveForm("server/customer/ProjectTrace.ashx?cmd=Save",this.$refs.form,this.form,this.switchLoading,result=> {
                    util.msgSuc("保存成功")
                    this.editFormVisible = false
                    this.$emit("onSaveSuc",this.form)
                })
            },
            linkManChange(val,record){
                let s = ""
                if(record.FPhone){
                    s += record.FPhone
                }
                if(record.FTelphone) {
                    if(s){
                        s += ","
                    }
                    s += record.FTelphone
                }
                this.form.FLinkPhone = s
            }
        },
        mounted() {

        }
    }
</script>
